#include <TFile.h>
#include <TTree.h>
#include <TH1D.h>
#include <iostream>
#include <TCanvas.h>
using namespace std;
void DrawnHit(int widcoin)
{
    gStyle->SetOptStat(111111);
    TFile *file = new TFile("../RootData/Coin_Sort_DAS2_data1_20250714T222403_0.root", "read");
    TTree *treeCoin = new TTree();
    TCanvas *c1 = new TCanvas("c1", "c1", 8000, 6000);
    c1->Divide(2, 4);
    TH1D *hHit[8];
    for (int i = 0; i < 8; i++)

    {
        hHit[i] = new TH1D(Form("hHit2_%d", i), Form("hHit_%d", widcoin), 10, 0, 10);
    }
    file->GetObject("treeCoin", treeCoin);
    short nHit[3][16];
    treeCoin->SetBranchAddress("nHit", nHit);
    for (int iEvent = 0; iEvent < treeCoin->GetEntries(); iEvent++)
    {
        treeCoin->GetEntry(iEvent);
        for (int i = 0; i < 8; i++)
        {
            if (nHit[2][i] > 0)
                hHit[i]->Fill(nHit[2][i]);
        }
    }
    for (int i = 0; i < 8; i++)
    {
        c1->cd(i + 1);
        hHit[i]->Draw();
    }

    c1->SetTitle(Form("hit_%d", widcoin));
    c1->SaveAs(Form("../RootData/Hit_%d.png", widcoin));
}
int main(int argc, char const *argv[])
{
    int widcoin = 100;
    if (argc > 1)
    {
        widcoin = std::atoi(argv[1]);
    }

    DrawnHit(widcoin);
    return 0;
}
